home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / source / chapter2 / isohex2_2 / isohex2_2.cpp next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  5.6 KB  |  226 lines

  1. /*****************************************************************************
  2. IsoHex2_2.cpp
  3. Ernest S. Pazera
  4. 12MAY2000
  5. Start a WIN32 Application Workspace, add in this file
  6. No other libs are required
  7. *****************************************************************************/
  8.  
  9. //////////////////////////////////////////////////////////////////////////////
  10. //INCLUDES
  11. //////////////////////////////////////////////////////////////////////////////
  12. #define WIN32_LEAN_AND_MEAN  
  13.  
  14. #include <windows.h>   
  15.  
  16. //////////////////////////////////////////////////////////////////////////////
  17. //DEFINES
  18. //////////////////////////////////////////////////////////////////////////////
  19. //name for our window class
  20. #define WINDOWCLASS "ISOHEX2"
  21. //title of the application
  22. #define WINDOWTITLE "IsoHex 2-2"
  23.  
  24. //////////////////////////////////////////////////////////////////////////////
  25. //PROTOTYPES
  26. //////////////////////////////////////////////////////////////////////////////
  27. bool Prog_Init();//game data initalizer
  28. void Prog_Loop();//main game loop
  29. void Prog_Done();//game clean up
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32. //GLOBALS
  33. //////////////////////////////////////////////////////////////////////////////
  34. HINSTANCE hInstMain=NULL;//main application handle
  35. HWND hWndMain=NULL;//handle to our main window
  36.  
  37. //////////////////////////////////////////////////////////////////////////////
  38. //WINDOWPROC
  39. //////////////////////////////////////////////////////////////////////////////
  40. LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  41. {
  42.     //which message did we get?
  43.     switch(uMsg)
  44.     {
  45.     //the mouse moved
  46.     case WM_MOUSEMOVE:
  47.         {
  48.             //if the left button is down
  49.             if(wParam & MK_LBUTTON)
  50.             {
  51.                 //extract x and y from lparam
  52.                 int x=LOWORD(lParam);
  53.                 int y=HIWORD(lParam);
  54.  
  55.                 //borrow the dc from the main window
  56.                 HDC hdc=GetDC(hWndMain);
  57.  
  58.                 //plot the pixel
  59.                 SetPixelV(hdc,x,y,RGB(255,255,255));
  60.  
  61.                 //return the dc to the system
  62.                 ReleaseDC(hWndMain,hdc);
  63.             }
  64.  
  65.             //handled, so return 0
  66.             return(0);
  67.         }break;
  68.     case WM_DESTROY://the window is being destroyed
  69.         {
  70.  
  71.             //tell the application we are quitting
  72.             PostQuitMessage(0);
  73.  
  74.             //handled message, so return 0
  75.             return(0);
  76.  
  77.         }break;
  78.     case WM_PAINT://the window needs repainting
  79.         {
  80.             //a variable needed for painting information
  81.             PAINTSTRUCT ps;
  82.             
  83.             //start painting
  84.             HDC hdc=BeginPaint(hwnd,&ps);
  85.  
  86.             /////////////////////////////
  87.             //painting code would go here
  88.             /////////////////////////////
  89.  
  90.             //end painting
  91.             EndPaint(hwnd,&ps);
  92.                         
  93.             //handled message, so return 0
  94.             return(0);
  95.         }break;
  96.     }
  97.  
  98.     //pass along any other message to default message handler
  99.     return(DefWindowProc(hwnd,uMsg,wParam,lParam));
  100. }
  101.  
  102.  
  103. //////////////////////////////////////////////////////////////////////////////
  104. //WINMAIN
  105. //////////////////////////////////////////////////////////////////////////////
  106. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
  107. {
  108.     //assign instance to global variable
  109.     hInstMain=hInstance;
  110.  
  111.     //create window class
  112.     WNDCLASSEX wcx;
  113.  
  114.     //set the size of the structure
  115.     wcx.cbSize=sizeof(WNDCLASSEX);
  116.  
  117.     //class style
  118.     wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  119.  
  120.     //window procedure
  121.     wcx.lpfnWndProc=TheWindowProc;
  122.  
  123.     //class extra
  124.     wcx.cbClsExtra=0;
  125.  
  126.     //window extra
  127.     wcx.cbWndExtra=0;
  128.  
  129.     //application handle
  130.     wcx.hInstance=hInstMain;
  131.  
  132.     //icon
  133.     wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
  134.  
  135.     //cursor
  136.     wcx.hCursor=LoadCursor(NULL,IDC_ARROW);
  137.  
  138.     //background color
  139.     wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
  140.  
  141.     //menu
  142.     wcx.lpszMenuName=NULL;
  143.  
  144.     //class name
  145.     wcx.lpszClassName=WINDOWCLASS;
  146.  
  147.     //small icon
  148.     wcx.hIconSm=NULL;
  149.  
  150.     //register the window class, return 0 if not successful
  151.     if(!RegisterClassEx(&wcx)) return(0);
  152.  
  153.     //create main window
  154.     hWndMain=CreateWindowEx(0,WINDOWCLASS,WINDOWTITLE, WS_BORDER | WS_SYSMENU | WS_VISIBLE,0,0,320,240,NULL,NULL,hInstMain,NULL);
  155.  
  156.     //error check
  157.     if(!hWndMain) return(0);
  158.  
  159.     //if program initialization failed, then return with 0
  160.     if(!Prog_Init()) return(0);
  161.  
  162.     //message structure
  163.     MSG msg;
  164.  
  165.     //message pump
  166.     for(;;)    
  167.     {
  168.         //look for a message
  169.         if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  170.         {
  171.             //there is a message
  172.  
  173.             //check that we arent quitting
  174.             if(msg.message==WM_QUIT) break;
  175.             
  176.             //translate message
  177.             TranslateMessage(&msg);
  178.  
  179.             //dispatch message
  180.             DispatchMessage(&msg);
  181.         }
  182.  
  183.         //run main game loop
  184.         Prog_Loop();
  185.     }
  186.     
  187.     //clean up program data
  188.     Prog_Done();
  189.  
  190.     //return the wparam from the WM_QUIT message
  191.     return(msg.wParam);
  192. }
  193.  
  194. //////////////////////////////////////////////////////////////////////////////
  195. //INITIALIZATION
  196. //////////////////////////////////////////////////////////////////////////////
  197. bool Prog_Init()
  198. {
  199.     ////////////////////////////////////
  200.     //your initialization code goes here
  201.     ////////////////////////////////////
  202.  
  203.     return(true);//return success
  204. }
  205.  
  206. //////////////////////////////////////////////////////////////////////////////
  207. //CLEANUP
  208. //////////////////////////////////////////////////////////////////////////////
  209. void Prog_Done()
  210. {
  211.     //////////////////////////
  212.     //clean up code goes here
  213.     //////////////////////////
  214. }
  215.  
  216. //////////////////////////////////////////////////////////////////////////////
  217. //MAIN GAME LOOP
  218. //////////////////////////////////////////////////////////////////////////////
  219. void Prog_Loop()
  220. {
  221.     ///////////////////////////
  222.     //main game logic goes here
  223.     ///////////////////////////
  224. }
  225.  
  226.